package anonymus.negocio;

//import java.sql.Date;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import anonymus.dao.horarioDAO;
import anonymus.excepcion.DAOExcepcion;
import anonymus.modelo.Horario;

public class HorarioNegocio {
	public Collection<Horario> CreaHorario(String fecha, String hInicio, String hFin,double tarifa,
			boolean promocionEspecial, String descripcionEspecial) throws ParseException {
		Collection<Horario> horarios = new ArrayList<Horario>();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		
		Date dia = df.parse(fecha);
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
		Date d = sdf.parse(hInicio);
		Long time = d.getTime();
		Time horaInicio = new Time(time);
		SimpleDateFormat sdfFin = new SimpleDateFormat("HH:mm:ss");
		Date dFin = sdfFin.parse(hFin);
		Long timeFin = dFin.getTime();
		Time horaFin = new Time(timeFin);
		java.sql.Date sqlDate = new java.sql.Date(dia.getTime());
		Horario h = new Horario(0,sqlDate,horaInicio,horaFin,tarifa,promocionEspecial,descripcionEspecial,null,null);
		horarios.add(h);
		return horarios;
	}
	public Collection<Horario> LlenaHorarios() throws ParseException {
		Collection<Horario> horarios = new ArrayList<Horario>();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date dia = df.parse("2012-04-01 00:00:00");
		//HORARIO-INICIO
		String sTime = "06:00:00";
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
		Date d = sdf.parse(sTime);
		Long time = d.getTime();
		Time horaInicio = new Time(time);
		//HORARIO-FIN
		String sTimeFin = "06:59:59";
		SimpleDateFormat sdfFin = new SimpleDateFormat("HH:mm:ss");
		Date dFin = sdfFin.parse(sTimeFin);
		Long timeFin = dFin.getTime();
		Time horaFin = new Time(timeFin);
		java.sql.Date sqlDate = new java.sql.Date(dia.getTime());
		Horario h = new Horario(0,sqlDate,horaInicio,horaFin,150.00,false,"",null,null);
		horarios.add(h);
		
		//HORARIO-INICIO
		sTime = "07:00:00";
		sdf = new SimpleDateFormat("HH:mm:ss");
		d = sdf.parse(sTime);
		time = d.getTime();
		horaInicio = new Time(time);
		//HORARIO-FIN
		sTimeFin = "07:59:59";
		sdfFin = new SimpleDateFormat("HH:mm:ss");
		dFin = sdfFin.parse(sTimeFin);
		timeFin = dFin.getTime();
		horaFin = new Time(timeFin);
		sqlDate = new java.sql.Date(dia.getTime());
		h = new Horario(0,sqlDate,horaInicio,horaFin,120.00,true,"PROMOCION PAGA UNO Y JUEGA TRES",null,null);
		horarios.add(h);
		
		//HORARIO-INICIO
		sTime = "08:00:00";
		sdf = new SimpleDateFormat("HH:mm:ss");
		d = sdf.parse(sTime);
		time = d.getTime();
		horaInicio = new Time(time);
		//HORARIO-FIN
		sTimeFin = "08:59:59";
		sdfFin = new SimpleDateFormat("HH:mm:ss");
		dFin = sdfFin.parse(sTimeFin);
		timeFin = dFin.getTime();
		horaFin = new Time(timeFin);
		sqlDate = new java.sql.Date(dia.getTime());
		h = new Horario(0,sqlDate,horaInicio,horaFin,180.00,false,"",null,null);
		horarios.add(h);
		//MASHORARIOS
		return horarios;
	}
	
	public Collection<Horario> LlenaHorarioAlquileres() throws ParseException {
		Collection<Horario> horarios = new ArrayList<Horario>();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date dia = df.parse("2012-04-01 00:00:00");
		//HORARIO-INICIO
		String sTime = "06:00:00";
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
		Date d = sdf.parse(sTime);
		Long time = d.getTime();
		Time horaInicio = new Time(time);
		//HORARIO-FIN
		String sTimeFin = "06:59:59";
		SimpleDateFormat sdfFin = new SimpleDateFormat("HH:mm:ss");
		Date dFin = sdfFin.parse(sTimeFin);
		Long timeFin = dFin.getTime();
		Time horaFin = new Time(timeFin);
		java.sql.Date sqlDate = new java.sql.Date(dia.getTime());
		Horario h = new Horario(0,sqlDate,horaInicio,horaFin,150.00,false,"",null,null);
		horarios.add(h);
		return horarios;
	}
	
	public Horario LlenaHorarioAlquiler() throws ParseException {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date dia = df.parse("2012-04-01 00:00:00");
		//HORARIO-INICIO
		String sTime = "06:00:00";
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
		Date d = sdf.parse(sTime);
		Long time = d.getTime();
		Time horaInicio = new Time(time);
		//HORARIO-FIN
		String sTimeFin = "06:59:59";
		SimpleDateFormat sdfFin = new SimpleDateFormat("HH:mm:ss");
		Date dFin = sdfFin.parse(sTimeFin);
		Long timeFin = dFin.getTime();
		Time horaFin = new Time(timeFin);
		java.sql.Date sqlDate = new java.sql.Date(dia.getTime());
		Horario h = new Horario(8,sqlDate,horaInicio,horaFin,150.00,false,"",null,null);
		return h;
	}
	
			
	public void insertarHorarios(int codigoCancha, Collection<Horario> horarios)  throws DAOExcepcion
	{
		for (Horario horario: horarios) {
			System.out.println("codCancha: " + codigoCancha);
			System.out.println("promo: " + horario.isPromocionEspecial() + " tarifa: " + horario.getTarifa()  + 
					" DescPromo: " + horario.getDescripcionPromocion() );
			
			horarioDAO dao = new horarioDAO();
			try {
				dao.insertar(horario);
				dao.insertarHasHorario(codigoCancha, horario.getCodHorario());
			} catch (DAOExcepcion e) {
				throw new DAOExcepcion("ERROR INSERTAR CANCHA");
			}
		}
	}
}
